package seed_partner_user

import (
	"fmt"
	"gitee.com/theegg/go-brick/app/model/user/users"
)

func InitUserSeed() {
	userArr := make([]users.UserAddParams, 0)

	userArr = append(userArr, users.UserAddParams{
		Username:    "ceshi001",
		Nickname:    "测试001",
		Pid:         0,
		Password:    "1234qwer",
		SecPassword: "1234qwer",
		UserType:    1,
		IsEditor:    0,
		IsTester:    0,
		IP:          "127.0.0.1",
	})

	userArr = append(userArr, users.UserAddParams{
		Username:    "editor001",
		Nickname:    "编辑001",
		Pid:         0,
		Password:    "1234qwer",
		SecPassword: "1234qwer",
		UserType:    1,
		IsEditor:    1,
		IsTester:    0,
		IP:          "127.0.0.1",
	})

	userArr = append(userArr, users.UserAddParams{
		Username:    "editor002",
		Nickname:    "编辑002",
		Pid:         0,
		Password:    "1234qwer",
		SecPassword: "1234qwer",
		UserType:    1,
		IsEditor:    1,
		IsTester:    0,
		IP:          "127.0.0.1",
	})

	userArr = append(userArr, users.UserAddParams{
		Username:    "sub_1_001",
		Nickname:    "sub_1_001",
		Pid:         1,
		Password:    "1234qwer",
		SecPassword: "1234qwer",
		UserType:    2,
		IsEditor:    1,
		IsTester:    0,
		IP:          "127.0.0.1",
	})

	userArr = append(userArr, users.UserAddParams{
		Username:    "sub_4_001",
		Nickname:    "sub_4_001",
		Pid:         4,
		Password:    "1234qwer",
		SecPassword: "1234qwer",
		UserType:    2,
		IsEditor:    1,
		IsTester:    0,
		IP:          "127.0.0.1",
	})

	count := 0
	errCount := 0
	for _, userParams := range userArr {
		var parent *users.Users
		var errGet error
		var err error
		if userParams.Pid > 0 {
			parent, errGet = users.GetItemById(userParams.Pid)
			if errGet != nil {
				fmt.Println(errGet.Error())
				errCount++
				continue
			}

			err = users.AddUserByParent(userParams, parent)
		} else {
			err = users.AddUserByAdmin(userParams, 0)
		}

		if err != nil {
			fmt.Println(err.Error())
			errCount++
		}
		count++
	}

	fmt.Printf("%5s|%25s|%10d|%8d|\n", "", "users", count, errCount)
}
